package cn.wenhe9.gulimall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.wenhe9.common.utils.ResultResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.wenhe9.gulimall.product.entity.CategoryBrandRelationEntity;
import cn.wenhe9.gulimall.product.service.CategoryBrandRelationService;



/**
 * 品牌分类关联
 *
 * @author dujinliang
 * @email dujinliang9@163.com
 * @date 2022-04-14 19:17:08
 */
@Slf4j
@Api(tags = "品牌分类关联")
@RestController
@RequestMapping("/api/product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 获取当前品牌关联的所有分类列表
     * @param brandId Long
     * @return ResultResponse
     */
    @GetMapping("/catelog/list")
    //@RequiresPermissions("product:categorybrandrelation:list")
    public ResultResponse list(@RequestParam("brandId") Long brandId){
        List<CategoryBrandRelationEntity> relationEntityList = categoryBrandRelationService.list(
                new QueryWrapper<CategoryBrandRelationEntity>().eq("brand_id", brandId)
        );

        return ResultResponse.ok(relationEntityList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:categorybrandrelation:info")
    public ResultResponse info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return ResultResponse.ok(categoryBrandRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:categorybrandrelation:save")
    public ResultResponse save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.saveDetail(categoryBrandRelation);

        return ResultResponse.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:categorybrandrelation:update")
    public ResultResponse update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return ResultResponse.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:categorybrandrelation:delete")
    public ResultResponse delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));
        log.info("id是{}", ids);

        return ResultResponse.ok();
    }

}
